/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */
#ifndef __QS_WidgetBase_H__
#define __QS_WidgetBase_H__

#include "Prerequisites.h"

#include "DiagramScene.h"

namespace QSThink
{
	class DiagramNode;

	class DiagramView;
	class DiagramViewListener
	{
	public:
		DiagramViewListener(DiagramView* view);
		~DiagramViewListener();
	protected:
		friend class DiagramView;
		virtual void OnTransactionChanged(Transaction* trans)=0;
		DiagramView* _view;
	};

	//for view diagram scene
	class DiagramView : 
		public QGraphicsView
	{
	public:
		static const int MAX_WIDTH=800;
		static const int MAX_HEIGHT=450;

		DiagramView();
		~DiagramView();

		int maxWidth(){
			return MAX_WIDTH;
		}

		int maxHeight(){
			return MAX_HEIGHT;
		}

		int getHighestPriceYPos();

		int getLowestPriceYPos();

		void load(QString symbol);

		void loadPriceEx(QString symbol);

		
		void load(QString symbol,QDate date);

		void loadCapital(QString symbol);

		void itemMoved();

		void OnEnterNode(DiagramNode* node);
		void OnLeaveNode(DiagramNode* node);

	protected:
		void keyPressEvent(QKeyEvent *event);
		void timerEvent(QTimerEvent *event);
		void wheelEvent(QWheelEvent *event);

		//void QWidget::mousePressEvent ( QMouseEvent * event )   [virtual protected]
		void mousePressEvent ( QMouseEvent * event );
		//virtual void mouseMoveEvent ( QMouseEvent * event )
		void mouseMoveEvent( QMouseEvent * event );


		void drawBackground(QPainter *painter, const QRectF &rect);

		void scaleView(qreal scaleFactor);
		void dragView( QPoint pt );
	protected:
		//
		int _timerId;
		DiagramScene* _scene;

		QPoint _midGlobalPos;//mid mouse press

	protected:
		friend class DiagramViewListener;
		void addListener(DiagramViewListener* l);
		void removeListener(DiagramViewListener* l);

		std::vector<DiagramViewListener*> _listeners;

	};
}
#endif
